

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Pelota {
	private static final int DIAMETER = 30;
	
	int x = 0; 
	int y = 0;
	int xa = 1;
	int ya = 1;
	private Principal game;

	public Pelota(Principal game) {
		this.game = game;
	}
	
	public void move() throws InterruptedException {
		if (x + xa < 0)
			xa = game.speed;
		else if (x + xa > game.getWidth() - DIAMETER)
			xa = -game.speed;
		
		else if (y + ya < 0)
			ya = game.speed;
		else if (y + ya > game.getHeight() - DIAMETER)
			game.gameOver();
		else if (collision()){
			ya = -game.speed;
			y = game.racquet.getTopY() - DIAMETER;
			
		}
		
		
		x = x + xa;
		y = y + ya;
	}

	private boolean collision() {
		boolean colision = game.racquet.getBounds().intersects(getBounds());
		if (colision)game.speed++;
		
		return colision;
	}

	public void paint(Graphics2D g) {
		g.setColor(Color.WHITE);
		g.fillOval(x, y, DIAMETER, DIAMETER);
		
	}

	public Rectangle getBounds() {
		return new Rectangle(x, y, DIAMETER, DIAMETER);
	}
	
	//testing
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getXa() {
		return xa;
	}
	public void setXa(int xa) {
		this.xa = xa;
	}
	public int getYa() {
		return ya;
	}
	public void setYa(int ya) {
		this.ya = ya;
	}

	public Principal getGame() {
		return game;
	}

	public void setGame(Principal game) {
		this.game = game;
	}

	public  int getDiameter() {
		return DIAMETER;
	}
	
	
}